using System;
using System.Collections.Generic;
using System.Text;
using Rapier.Kodachi.Shared;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;
using System.Drawing;

namespace Rapier.Kodachi.Core.Actions
{
    public class RevealTarget : Action
    {
        #region Constructor
        public RevealTarget(Plugin plugin)
            : base(plugin, "Rapier.CorePlugin.RevealTarget", "Reveal Target", "Opens the folder containing the shortcut item's target file.")
        {
            GetImage = delegate() { return CoreCatalog.GetImageFromPath(String.Empty); };
        }
        #endregion

        #region Action Members
        public override bool IsValidDirect(Item directItem)
        {
            return directItem.Properties.ContainsKey("ShortcutTarget");
        }

        public override void Execute(Item[] directItems, Item[] indirectItems)
        {
            foreach (Item directItem in directItems)
            {
                string path = System.IO.Path.GetDirectoryName(directItem.Properties["ShortcutTarget"].ToString());
                Launch(path);
            }
        }
        #endregion

        #region Protected Methods
        protected virtual void Launch(string path)
        {
            ProcessStartInfo psi = new ProcessStartInfo(path);
            psi.UseShellExecute = true;
            Process.Start(psi);
        }
        #endregion
    }
}
